const multer = require('multer');
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    //指定文件保存路径
    cb(null, "./public/uploads"); //注意路径，以“.”开头
  },
  filename: function (req, file, cb) {
    //指定文件名和拓展名
    // console.log(file.originalname)  // "1.jpg"
    var fileFormat = (file.originalname).split("."); //originalname：文件名 ["13243534543","jpg"]
    //通过回调函数为上传的文件重命名
    cb(null, fileFormat[0].slice(0, 5) + "-" + Date.now() + "." + fileFormat[fileFormat.length - 1]);
    //'1-234523534534.jpg'
  }
});

//公开配置
const upload = multer({
  storage:storage
});
module.exports = upload;